import 'package:flutter/material.dart';

class HorizontalIconList extends StatelessWidget {
  const HorizontalIconList({super.key});

  final List<IconData> icons = const [
    Icons.home,
    Icons.work,
    Icons.school,
    Icons.shopping_cart,
    Icons.restaurant,
    Icons.directions_car,
  ];

  final List<String> titles = const[
    'Home',
    'Work',
    'School',
    'Shopping',
    'Restaurant',
    'Car',
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(8),
      height: 120,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        physics: const BouncingScrollPhysics(), //添加一点惯性移动效果
        itemCount: icons.length,
        itemBuilder: (context, index) {
          return Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              children: [
                Icon(
                  icons[index],
                  size: 50,
                ),
                const SizedBox(height: 5),
                Text(
                  titles[index],
                  style: const TextStyle(fontSize: 14),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}